package com.codinbros.session001.controller;

import java.util.ArrayList;

import processing.core.PApplet;
import processing.core.PVector;

import com.codinbros.session001.interfaces.Citizen;
import com.codinbros.session001.interfaces.Flocking;
import com.codinbros.session001.model.ForceField;

public class Flock implements Flocking {
	private ArrayList<Citizen> flockMembers;
	private ForceField forceField;
	private boolean paused;
	private PApplet g;
	private PVector velocity;
	private PVector accelecation;
	private float maxSpeed;
	private float maxForce;
	private FlockingBehaviour flockingBehaviour;

	public Flock() {
		flockMembers = new ArrayList<>();
		flockingBehaviour = new FlockingBehaviour();
		flockingBehaviour.addFlock(flockMembers);
	}

	public void draw() {
		if (!paused){
			for (Citizen citizen : flockMembers) {
				citizen = flockingBehaviour.flock(citizen);
			}
			for (Citizen citizen : flockMembers) {
				citizen.draw();
			}
		}
	}

	@Override
	public void affect(PVector force) {
		// TODO Auto-generated method stub
	}

	@Override
	public ForceField getEffect() {
		return forceField;
	}

	@Override
	public PVector getPostition() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setPosition(PVector position) {
		// TODO Auto-generated method stub

	}

	@Override
	public void terminate() {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		paused = true;
	}

	@Override
	public void resume() {
		paused = false;
	}

	@Override
	public ArrayList<Citizen> getFlockMembers() {
		// TODO Auto-generated method stub
		return flockMembers;
	}

	@Override
	public void setFlockMembers(ArrayList<Citizen> flock) {
		flockMembers = flock;

	}

	@Override
	public void addFlockMember(Citizen member) {
		member.setPapplet(g);
		flockMembers.add(member);

	}

	@Override
	public void removeFlockMember(Citizen member) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setPapplet(PApplet da) {
		this.g = da;
	}

	@Override
	public PVector getVelocity() {
		return velocity;
	}

	@Override
	public void setVelocity(PVector velocity) {
		this.velocity = velocity;
	}

	@Override
	public void setMaxSpeed(float maxSpeed) {
		this.maxSpeed = maxSpeed;

	}

	@Override
	public float getMaxSpeed() {
		return maxSpeed;
	}

	@Override
	public void setMaxForce(float maxForce) {
		this.maxForce = maxForce;

	}

	@Override
	public float getMaxForce() {
		return maxForce;
	}

	@Override
	public PVector getAccellectaion() {
		return accelecation;
	}

	@Override
	public void setAccelleration(PVector acelleration) {
		this.accelecation = acelleration;
	}

}
